package com.rill.dao;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.rill.po.ArticleClickNum;

public class ArticleClickNumDaoImpl extends HibernateDaoSupport implements ArticleClickNumDao{

	/*根据id\ip\时间查询文章点击量
	 */
	@Override
	public List queryById(int artId,String ip, Date time) {
		return this.getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session.createQuery("select click from article_click click where click.artId= ? and click.ip = ? and click.time = ?");
				//设置参数
				query.setParameter(0, artId);
				query.setParameter(1, ip);
				query.setParameter(2, time);
				return query.list();
			}
		});

	}
	/*添加文章点击记录
	 */
	@Override
	public void addVistRecord(ArticleClickNum artclick) {
		this.getHibernateTemplate().save(artclick);//添加点击量记录
		
	}

}
